// Date Validation and Format Javascript
// copyright 11th June 2007 by Stephen Chapman
// permission to use this Javascript on your web page is granted
// provided that all of the code in this script (including these
// comments) is used without any alteration
// you may swap the 12 and 31 around if you want mm/dd instead of dd/mm
var daNow=new Date();
function dtval(d,e) {
var pK = e ? e.which : window.event.keyCode;
if (pK == 8) {d.value = substr(0,d.value.length-1); return;}
var dt = d.value;
var da = dt.split('/');
for (var a = 0; a < da.length; a++) {if (da[a] != +da[a]) da[a] = da[a].substr(0,da[a].length-1);}
if (da[0] > 31) {da[1] = da[0].substr(da[0].length-1,1);da[0] = '0'+da[0].substr(0,da[0].length-1);}
if (da[1] > 12) {da[2] = da[1].substr(da[1].length-1,1);da[1] = '0'+da[1].substr(0,da[1].length-1);}
if (da[2] > 9999) da[1] = da[2].substr(0,da[2].length-1);
dt = da.join('/');
//if (dt.length == 2 || dt.length == 5) dt += '/';
if (dt.length == 2) dt += '/';
if (dt.length == 5) dt += '/'+ daNow.getFullYear();
d.value = dt;
}
function setFocus(d)
{
    dt=d.value;
    if (dt.length <10 && dt.length>0) 
    {
    alert("Nhập theo định dạng: dd/MM/yyyy")
    d.focus();
    }
}

// JScript File
var aRequires = new Array();
var aRequireMessages = new Array();

function AddRequire(oControlName, strMessage){
	aRequires[aRequires.length] = oControlName;
	aRequireMessages[aRequireMessages.length] = strMessage;
}

var aDiffs = new Array();
var aDiffMessages = new Array();
function AddDiff(oControlName, strMessage){
	aDiffs[aDiffs.length] = oControlName;
	aDiffMessages[aDiffMessages.length] = strMessage;
}

var aIntergers = new Array();
var aIntergerMessages = new Array();

function AddInteger(oControlName, strMessage){
	aIntergers[aIntergers.length] = oControlName;
	aIntergerMessages[aIntergerMessages.length] = strMessage;
}

var aPositiveIntergers = new Array();
var aPositiveIntergerMessages = new Array();

function AddPositiveInteger(oControlName, strMessage){
	aPositiveIntergers[aPositiveIntergers.length] = oControlName;
	aPositiveIntergerMessages[aPositiveIntergerMessages.length] = strMessage;
}

var aNegativeIntergers = new Array();
var aNegativeIntergerMessages = new Array();

function AddNegativeInteger(oControlName, strMessage){
	aNegativeIntergers[aNegativeIntergers.length] = oControlName;
	aNegativeIntergerMessages[aNegativeIntergerMessages.length] = strMessage;
}

var aNonNegativeIntergers = new Array();
var aNonNegativeIntergerMessages = new Array();

function AddNonNegativeInteger(oControlName, strMessage){
	aNonNegativeIntergers[aNonNegativeIntergers.length] = oControlName;
	aNonNegativeIntergerMessages[aNonNegativeIntergerMessages.length] = strMessage;
}

var aFloats = new Array();
var aFloatMessages = new Array();

function AddFloat(oControlName, strMessage){
	aFloats[aFloats.length] = oControlName;
	aFloatMessages[aFloatMessages.length] = strMessage;
}

// not implemented yet
var aRanges = new Array();
var aRangeMins = new Array();
var aRangeMaxs = new Array();
var aRangeMessages = new Array();

function AddRange(oControlName, min_value, max_value, strMessage){
	aRanges[aRanges.length] = oControlName;
	aRangeMessages[aRangeMessages.length] = strMessage;
	aRangeMins[aRangeMins.length] = min_value;
	aRangeMaxs[aRangeMaxs.length] = max_value;
}

var aUSDates = new Array();
var aUSDateMessages = new Array();

function AddUSDate(oControlName, strMessage){
	aUSDates[aUSDates.length] = oControlName;
	aUSDateMessages[aUSDateMessages.length] = strMessage;
}

var aEUDates = new Array();
var aEUDateMessages = new Array();

function AddEUDate(oControlName, strMessage){
	aEUDates[aEUDates.length] = oControlName;
	aEUDateMessages[aEUDateMessages.length] = strMessage;
}

// not implemented yet
var aTimes = new Array();
var aTimeMessages = new Array();

function AddTime(oControlName, strMessage){
	aTimes[aTimes.length] = oControlName;
	aTimeMessages[aTimeMessages.length] = strMessage;
}

// not implemented yet
var aBooleans = new Array();
var aBooleanMessages = new Array();

function AddBoolean(oControlName, strMessage){
	aBooleans[aBooleans.length] = oControlName;
	aBooleanMessages[aBooleanMessages.length] = strMessage;
}
// not implemented yet
var aTelephones = new Array();
var aTelephoneMessages = new Array();

function AddTelephone(oControlName, strMessage){
	aTelephones[aTelephones.length] = oControlName;
	aTelephoneMessages[aTelephoneMessages.length] = strMessage;
}
// not implemented yet
var aZipCodes = new Array();
var aZipCodeMessages = new Array();

function AddZipCode(oControlName, strMessage){
	aZipCodes[aZipCodes.length] = oControlName;
	aZipCodeMessages[aZipCodeMessages.length] = strMessage;
}
// not implemented yet
var aCreditCards = new Array();
var aCreditCardMessages = new Array();

function AddCreditCard(oControlName, strMessage){
	aCreditCards[aCreditCards.length] = oControlName;
	aCreditCardMessages[aCreditCardMessages.length] = strMessage;
}
// not implemented yet
var aSSNs = new Array();
var aSSNMessages = new Array();

function AddSSN(oControlName, strMessage){
	aSSNs[aSSNs.length] = oControlName;
	aSSNMessages[aSSNMessages.length] = strMessage;
}

var aEmails = new Array();
var aEmailMessages = new Array();

function AddEmail(oControlName, strMessage){
	aEmails[aEmails.length] = oControlName;	
	aEmailMessages[aEmailMessages.length] = strMessage;
}
// not implemented yet
var aURLs = new Array();
var aURLMessages = new Array();

function AddURL(oControlName, strMessage){
	aURLs[aURLs.length] = oControlName;
	aURLMessages[aURLMessages.length] = strMessage;
}
// not implemented yet
var aGUIDs = new Array();
var aGUIDMessages = new Array();

function AddGUID(oControlName, strMessage){
	aGUIDs[aGUIDs.length] = oControlName;
	aGUIDMessages[aGUIDMessages.length] = strMessage;
}
// not implemented yet
var aUUIDs = new Array();
var aUUIDMessages = new Array();

function AddUUID(oControlName, strMessage){
	aUUIDs[aUUIDs.length] = oControlName;
	aUUIDMessages[aUUIDMessages.length] = strMessage;
}
// not implemented yet
var aNoBlanks = new Array();
var aNoBlankMessages = new Array();

function AddNoBlank(oControlName, strMessage){
	aNoBlanks[aNoBlanks.length] = oControlName;
	aNoBlankMessages[aNoBlankMessages.length] = strMessage;
}
// not implemented yet
var aSubmitOnces = new Array();
var aSubmitOnceMessages = new Array();

function AddSubmitOnce(oControlName, strMessage){
	aSubmitOnces[aSubmitOnces.length] = oControlName;
	aSubmitOnceMessages[aSubmitOnceMessages.length] = strMessage;
}
// not implemented yet
var aPatterns = new Array();
var aPatternMessages = new Array();

function AddPattern(oControlName, strMessage){
	aPatterns[aPatterns.length] = oControlName;
	aPatternMessages[aPatternMessages.length] = strMessage;
}

function ValidateControls(objForm)
{
    var retVal = true;
    var bFirstControl =  true;
    var strMessages = "";
	
    for (iii=0; iii < aRequires.length; iii++){
        var strName = aRequires[iii];
        var strMessage = aRequireMessages[iii];
        if (objForm[strName] != null)
        {
            if (objForm[strName].value == "")
            {
                if (bFirstControl) objForm[strName].focus();
                bFirstControl = false;
                retVal = false;
                strMessages += strMessage + "\n\r";
            }
        }
	}
	for (iii=0; iii < aDiffs.length; iii++){
        var strName = aDiffs[iii];
        var strMessage = aDiffMessages[iii];
		var strValue = "";
		if (strName.indexOf(":") > 0)
		{
			var arrNameValues = strName.split(":");
			strName = arrNameValues[0];
			strValue = arrNameValues[1];
		}
        if (objForm[strName] != null)
        {
            if (!isDiff(objForm[strName].value, strValue))
            {
                if (bFirstControl) objForm[strName].focus();
                bFirstControl = false;
                retVal = false;
                strMessages += strMessage + "\n\r";
            }
        }
	}
	for (iii=0; iii < aIntergers.length; iii++){
        var strName = aIntergers[iii];
        var strMessage = aIntergerMessages[iii];
        if (objForm[strName] != null)
        {
            if (!IsInteger(objForm[strName].value))
            {
                if (bFirstControl) objForm[strName].focus();
                bFirstControl = false;
                retVal = false;
                strMessages += strMessage + "\n\r";
            }
        }
	}
	for (iii=0; iii < aPositiveIntergers.length; iii++){
        var strName = aPositiveIntergers[iii];
        var strMessage = aPositiveIntergerMessages[iii];
        if (objForm[strName] != null)
        {
            if ( (!IsInteger(objForm[strName].value)) || (!IsPositiveNumber(objForm[strName].value)) )
            {
                if (bFirstControl) objForm[strName].focus();
                bFirstControl = false;
                retVal = false;
                strMessages += strMessage + "\n\r";
            }
        }
	}
	for (iii=0; iii < aNegativeIntergers.length; iii++){
        var strName = aNegativeIntergers[iii];
        var strMessage = aNegativeIntergerMessages[iii];
        if (objForm[strName] != null)
        {
            if ( (!IsInteger(objForm[strName].value)) || (IsNonNegativeNumber(objForm[strName].value)) )
            {
                if (bFirstControl) objForm[strName].focus();
                bFirstControl = false;
                retVal = false;
                strMessages += strMessage + "\n\r";
            }
        }
	}
	
	for (iii=0; iii < aNonNegativeIntergers.length; iii++){
        var strName = aNonNegativeIntergers[iii];
        var strMessage = aNonNegativeIntergerMessages[iii];
        if (objForm[strName] != null)
        {
            if ( (!IsInteger(objForm[strName].value)) || (!IsNonNegativeNumber(objForm[strName].value)) )
            {
                if (bFirstControl) objForm[strName].focus();
                bFirstControl = false;
                retVal = false;
                strMessages += strMessage + "\n\r";
            }
        }
	}
	
	for (iii=0; iii < aFloats.length; iii++){
        var strName = aFloats[iii];
        var strMessage = aFloatMessages[iii];
        if (objForm[strName] != null)
        {
            if (!IsNumber(objForm[strName].value))
            {
                if (bFirstControl) objForm[strName].focus();
                bFirstControl = false;
                retVal = false;
                strMessages += strMessage + "\n\r";
            }
        }
	}
	
	for (iii=0; iii < aUSDates.length; iii++){
        var strName = aUSDates[iii];
        var strMessage = aUSDateMessages[iii];
        if (objForm[strName] != null)
        {
            if ((objForm[strName].value != "")&&(!IsDate(objForm[strName].value)))
            {
                if (bFirstControl) objForm[strName].focus();
                bFirstControl = false;
                retVal = false;
                strMessages += strMessage + "\n\r";
            }
        }
	}
	
	for (iii=0; iii < aEUDates.length; iii++){
        var strName = aEUDates[iii];
        var strMessage = aEUDateMessages[iii];
        if (objForm[strName] != null)
        {
            if ((objForm[strName].value != "")&&(!IsDateFR(objForm[strName].value)))
            {
                if (bFirstControl) objForm[strName].focus();
                bFirstControl = false;
                retVal = false;
                strMessages += strMessage + "\n\r";
            }
        }
	}

	for (iii=0; iii < aEmails.length; iii++){
        var strName = aEmails[iii];
        var strMessage = aEmailMessages[iii];
        if (objForm[strName] != null)
        {
            if (objForm[strName].value == "")
            {
                if (bFirstControl) objForm[strName].focus();
                bFirstControl = false;
                retVal = false;
                strMessages += strMessage + "\n\r";
            }
            if (!IsEmailAddress(objForm[strName].value))
            {
                if (bFirstControl) objForm[strName].focus();
                bFirstControl = false;
                retVal = false;
                strMessages += strMessage + "\n\r";
            }
        }
	}
	
	if (strMessages != "") alert (strMessages);
	return retVal;	
}


function Trim(strval)
{
	var intLeft, intRight;	
	strvar = new String(strval);	
	if (strvar.length==1 && strvar==" ") return "";	
	
	intLeft = 0;
	while ((strvar.charAt(intLeft) == " ") && (intLeft<strvar.length)) intLeft++;	
	intRight = strvar.length-1;
	while ((strvar.charAt(intRight) == " ") && (intRight>0)) intRight--;
	
	if (intRight>=intLeft) {
		return strvar.substring(intLeft,intRight+1);
	} else {
		return "";
	}	
}
//Check number value
function IsNumber(numberVal)
{
	numberVal = Trim(numberVal);
	if (numberVal== "") return false;
	if (isNaN(numberVal))
		return false;
	return true;
}
//Check positive number
function IsPositiveNumber(numberVal)
{
	if(!IsNumber(numberVal)) return false;
	var Temp = eval(numberVal)*1;
	if(Temp <= 0) return false;
	return true;
}
//Check non-negative number
function IsNonNegativeNumber(numberVal)
{
	if(!IsNumber(numberVal)) return false;
	var Temp = eval(numberVal)*1;
	if(Temp < 0) return false;
	return true;
}
//Check Float value
function IsFloat(numberVal)
{
	var testNumber = new Number(parseFloat(numberVal));
	
	if (Trim(numberVal)!= ""){
		if (isNaN(numberVal)  || (Trim(testNumber.toString())!=Trim(numberVal)))
			return false;
			
	}
	return true
}
//Check Integer value
function IsInteger(numberVal)
{
	var testNumber = new Number(parseInt(numberVal));
	
	if (Trim(numberVal)!= ""){
		if (isNaN(numberVal)  || (Trim(testNumber.toString())!=Trim(numberVal)))
			return false;
			
	}
	return true;
}
//Check Positive Integer
function IsPositiveInteger(numberVal){
	if(!IsInteger(numberVal)) return false;
	var Temp = eval(numberVal)*1;
	if(Temp < 0) return false;
	return true;
}
//Check date value with format MM/yyyy and refine to valid format
function validDate(strDate){
	var intPos = strDate.search('/');
	var strMonth;
	if(intPos > 0)
	{
		strMonth = strDate.substr(0, intPos);
		if(!IsNumber(strMonth)) return false;
		if(eval(strMonth) <= 0 || eval(strMonth) > 12)
		{
			return false;
		}
		
		strYear = strDate.substr(intPos + 1);
		if(!IsNumber(strYear)) return false;
		if(eval(strYear) < 1980 || eval(strYear) > 2200)
		{
			return false;
		}
	}
	return true;
}
//Check date value with format input
function IsDateFormat(strDate,strFormat)
{
	if (strFormat=="mm/dd/yyyy")
	{
		return IsDate(strDate);
	}
	else
	{
		return IsDateFR(strDate);
	}
}
//Check date value with format dd/MM/yyyy and refine to valid format
function IsDateFR(strDate)
{
	if ((strDate.length>10)||(strDate.length<8)) return false;
	intDash = strDate.search("/");
	if (intDash == -1) return false;
	else
	{
		strTemp = strDate.substr(0,intDash);
		if ((strTemp.charAt(0) == "0")&&(strTemp.length>1)) strTemp = strTemp.substr(1);
		if (IsNumber(strTemp)==false) return false;
		else
		{	
			intDay = parseInt(strTemp);
		}	
		strDate = strDate.substr(intDash+1);
	}
	intDash = strDate.search("/");
	if (intDash == -1) return false;
	else
	{
		strTemp = strDate.substr(0,intDash);
		if ((strTemp.charAt(0) == "0")&&(strTemp.length>1)) strTemp = strTemp.substr(1);
		if (IsNumber(strTemp)==false) return false;
		else
		{
			intMonth = parseInt(strTemp);
			//Kiem tra thang nhap vao
			if ((intMonth<1)||(intMonth>12))	return false;
			intDayN = 30;
			if ((intMonth<8)&&(intMonth % 2 == 1)) intDayN = 31;
			if ((intMonth>7)&&(intMonth % 2 == 0)) intDayN = 31;
			//Kiem tra ngay nhap vao
			if ((intDay<1)||(intDay>intDayN)) return false;
		}	
		strDate = strDate.substr(intDash+1);
	}	
	if (IsNumber(strDate)==false) return false;
	else
	{	
		intYear = parseInt(strDate);
		if ((intYear<1900)||(intYear>2100)) return false;
	}	
	if (intMonth==2)
	{
		if (intYear % 4 == 0) intDayN = 29;
		else intDayN = 28;
		if (intDay > intDayN) return false;
	}
	strTemp = "";
	if (intDay<10) strTemp = strTemp + "0" + intDay + "/";
	else strTemp = strTemp + intDay + "/";
	if (intMonth<10) strTemp = strTemp + "0" + intMonth + "/";
	else strTemp = strTemp + intMonth + "/";	
	strTemp = strTemp + intYear;
	strDate = strTemp;
	return true;
}
//Check date value with format MM/dd/yyyy and refine to valid format
function IsDate(strDate)
{
	if ((strDate.length>10)||(strDate.length<8)) return false
	intDash = strDate.search("/")
	if (intDash == -1) return false
	else
	{
		strTemp = strDate.substr(0,intDash)
		if ((strTemp.charAt(0) == "0")&&(strTemp.length>1)) strTemp = strTemp.substr(1)
		if (IsNumber(strTemp)==false) return false
		else
		{	
			intMonth = parseInt(strTemp)
			if ((intMonth<1)||(intMonth>12))	return false
			intDayN = 30
			if ((intMonth<8)&&(intMonth % 2 == 1)) intDayN = 31
			if ((intMonth>7)&&(intMonth % 2 == 0)) intDayN = 31
		}	
		strDate = strDate.substr(intDash+1)
	}
	intDash = strDate.search("/")
	if (intDash == -1) return false
	else
	{
		strTemp = strDate.substr(0,intDash)
		if ((strTemp.charAt(0) == "0")&&(strTemp.length>1)) strTemp = strTemp.substr(1)
		if (IsNumber(strTemp)==false) return false
		else
		{
			intDay = parseInt(strTemp)
			if ((intDay<1)||(intDay>intDayN)) return false	
		}	
		strDate = strDate.substr(intDash+1)
	}	
	if (IsNumber(strDate)==false) return false
	else
	{	
		intYear = parseInt(strDate)
		if ((intYear<1900)||(intYear>2100)) return false		
	}	
	if (intMonth==2)
	{
		if (intYear % 4 == 0) intDayN = 29
		else intDayN = 28
		if (intDay > intDayN) return false
	}
	strTemp = ""
	if (intMonth<10) strTemp = strTemp + "0" + intMonth + "/"
	else strTemp = strTemp + intMonth + "/"
	if (intDay<10) strTemp = strTemp + "0" + intDay + "/"
	else strTemp = strTemp + intDay + "/"
	strTemp = strTemp + intYear
	strDate = strTemp
	return true
}
//Compare 2 date 
function Compare(ct1,ct2,dtformat)//true ct1.value>=ct2.value else false
{
	if ((ct1=="")||(ct2==""))
	{
		return true;
	}
	else
	{
		var date1
		var date2
		var month1
		var month2
		var year1
		var year2
		tempdtFormat=dtformat;
		
		formatChar = " "
		aFormat	= tempdtFormat.split(formatChar)
		if (aFormat.length<3)
		{
			formatChar = "/"
			aFormat	= tempdtFormat.split(formatChar)				
		}

	
		aData1 =	ct1.split(formatChar)
		aData2 = 	ct2.split(formatChar)
		for	(i=0;i<3;i++)
		{
			if ((aFormat[i]=="d") || (aFormat[i]=="dd"))
			{
				date1 = parseInt(aData1[i], 10)
				date2 = parseInt(aData2[i], 10)
			}
			else if	((aFormat[i]=="m") || (aFormat[i]=="mm"))
			{
				month1 =	parseInt(aData1[i], 10) - 1
				month2 =	parseInt(aData2[i], 10) - 1							
			}
			else if	(aFormat[i]=="yyyy")
			{
				year1 = parseInt(aData1[i], 10)
				year2 = parseInt(aData2[i], 10)							
			}						
		}
		if (year2>year1)			
		{
			return false;
		}
		else
		{
			if (year2==year1)
			{
				if(month2 > month1)
				{
					return false;
				}
				else
				{
					if (month2==month1)
					{
						if (date2 > date1)
						{
							return false;
						}
						else
						{
							return true;
						}
					}
					else
					{
						return true;
					}
				}
			}
			else
			{
				return true;
			}
		}
	}
}
//Compare two Date
function CompareDate(strDate1, strDate2)
{
var day1, day2, month1, month2, year1, year2;
if (IsDate(strDate1)==false) return false
if (IsDate(strDate2)==false) return false

	intDash1 = strDate1.search("/")
	if (intDash1 == -1) return false
	else
	{
		strTemp1 = strDate1.substr(0,intDash1)
		month1 = strTemp1;
		strDate1 = strDate1.substr(intDash1+1)
	}
	intDash1 = strDate1.search("/")
	if (intDash1 == -1) return false
	else
	{
		strTemp1 = strDate1.substr(0,intDash1)		
		day1 = strTemp1;				
		strDate1 = strDate1.substr(intDash1+1)
	}	
	
	if (IsNumber(strDate1)==false) return false
	else
	{	
		intYear1 = parseInt(strDate1)
		if ((intYear1<1900)||(intYear1>2100)) return false		
		year1 = intYear1;
	}	
	intDash2 = strDate2.search("/")
	if (intDash2 == -1) return false
	else
	{
		strTemp2 = strDate2.substr(0,intDash2)
		month2 = strTemp2;
		strDate2 = strDate2.substr(intDash2+1)
	}
	intDash2 = strDate2.search("/")
	
	if (intDash2 == -1) return false
	else
	{
		strTemp2 = strDate2.substr(0,intDash2)		
		day2 = strTemp2;				
		strDate2 = strDate2.substr(intDash2+1)
	}	
	
	if (IsNumber(strDate2)==false) return false
	else
	{	
		intYear2 = parseInt(strDate2)
		if ((intYear2<1900)||(intYear2>2100)) return false		
		year2 = intYear;
	}	
	
	if (year2<year1) return false;
	
	if (year2==year1)
		{
		if (month2<month1) return false;
		
		if (month2==month1)
			{
			if (day2<day1) return false;	
			}
		}
	
	return true
}
//Check empty string
function IsEmpty(stringVal)
{
	stringVal = Trim(stringVal);
	if(stringVal.length==0)
		return true;
	else
		return false;
}

//Check e-mail address
function IsEmailAddress (strEmail)
{                                       
	var v = Trim(strEmail);
	if (v.length==0) return true;
	var at_i = v.indexOf("@");          
	if (at_i > 0) {                     
	  var dot_i = v.indexOf(".", at_i);   
	  if ((dot_i == -1) || (dot_i==at_i+1))
	    return false;               
	}
	else
	  return false;                   

	return true;
}                                       

function IsNumeric(type,sText)
{
	if (type==1){
	   var ValidChars = "0123456789";
	}
	if (type==2){
	   var ValidChars = "0123456789.";
	}
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
	  { 
	  Char = sText.charAt(i); 
	  if (ValidChars.indexOf(Char) == -1) 
		 {
		 IsNumber = false;
		 }
	  }
   return IsNumber;
   }

// format a value as currency. 
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	
	if(isNaN(num))
	   num = "0";
	   
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	
	if(cents<10)
		cents = "0" + cents;
		
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3)) + ',' + num.substring(num.length-(4*i+3));
		
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

// format a value as number. 
function formatNumber(num) {
	num = num.toString().replace(/\$|\,/g,'');
	
	if(isNaN(num))
	   num = "0";
	   
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	
	if(cents<10)
		cents = "0" + cents;
		
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3)) + ',' + num.substring(num.length-(4*i+3));
		
	return (((sign)?'':'-') + num + '.' + cents);
}

<!-- Function Description:  Validates Non Currency fields. --> 
function validateDollar( fld ) 
{ 	
   var temp_value = fld.value; 
   	
   if (temp_value == "") 
   { 
     fld.value = "$0.00"; 
     return; 
   } 
   var Chars = "0123456789.,$-"; 
   for (var i = 0; i < temp_value.length; i++) 
   { 
       if (Chars.indexOf(temp_value.charAt(i)) == -1) 
       {                     
           return false; 
       } 
   } 
   return true;
} 

function URLDecode(encoded)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
	   var ch = encoded.charAt(i);
	   if (ch == "+") {
		   plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   
   return plaintext;
}

function URLEncode( plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";


	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
		if (ch == " ") {
			encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
			encoded += ch;
		} else {
			var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
				alert( "Unicode Character '" 
						+ ch 
						+ "' cannot be encoded using standard URL encoding.\n" +
						  "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	
	return encoded;
}
	
function isDiff(value1, value2) 
{ 	   	
   if (value1 == value2) 
   { 
     return false; 
   }    
   return true;
}

